$(function () {
    gitUserInfo()
    $('#logout').on('click', function () {
        layer.confirm('你确定要推出吗？', {icon: 3, title:'提示'}, function(index){
            //do something
            localStorage.removeItem('token')
            location.href = '/login.html'
            layer.close(index);
          });
    })
})
function gitUserInfo() {
    axios({
        url:'/my/userinfo',
        method: 'get',
        // headers: {
        //     Authorization:localStorage.getItem('token')
        // }
    }).then(res=>{
        //成功回调
        console.log(res)
        if (res.data.status != 0) {
            return layer.msg(res.data.message)
        }
        renderAvatar(res.data.data)
    });
}
function renderAvatar(user) {
    let name = user.nickname || user.username
    $('.welcome').html('欢迎' + name)
    if (user.user_pic != null) {
        $('.layui-nav-img').show().attr('src', user.user_pic)
        $('.avatar-text').hide()
    } else {
        $('.layui-nav-img').hide()
        let first = name[0].toUpperCase()
        $('.avatar-text').show().html(first)
    }
}